<template>
  <view class="detail">
    <plantDetail :plantInfo="plantList" type="detail"></plantDetail>
    <u-back-top :scroll-top="scrollTop"></u-back-top>
  </view>
</template>

<script>
  import {
    mapState
  } from 'vuex';
  import {
    loading,
    successToast,
    clearLoad,
    init
  } from '@/common/global.js'
  import api from '@/common/api.js';
  import plantDetail from '@/components/plant-detail.vue'
  export default {
    components: {
      plantDetail
    },
    data() {
      return {
        plantList: null,
        scrollTop: 0
      };
    },
    computed: {
      ...mapState({
        personInfo: state => state.personInfo,
        loginStatus: state => state.loginStatus
      })
    },
    methods: {
      // 根据id获取植物信息
      getPlantReq(params) {
        api.getPlantById(params, res => {
          if (res.data.status === 0) {
            let json = res.data.data
            this.plantList = {
              id: json.botanyId,
              doorId: json.doorId,
              outlineId: json.outlineId,
              sectionId: json.sectionId,
              genusId: json.genusId,
              name: json.name,
              src: json.src,
              time: json.time,
              info: [json.baseInfo, json.formInfo, json.growInfo],
              cultivateInfo: json.cultivateInfo
            }
            console.log(this.plantList)
          }
        })
      },
      // 历史记录请求
      historyReq(params1) {
        api.addHistory(params1)
      }
    },
    onPageScroll(e) {
      this.scrollTop = e.scrollTop;
    },
    onLoad(options) {
      let params = {
        botanyId: options.botanyId,
      }
      this.getPlantReq(params)
      if (!this.loginStatus) {
        return;
      }
      let params1 = {
        botanyId: options.botanyId,
        phone: this.personInfo.phone,
        token: this.personInfo.token
      }
      this.historyReq(params1)
    },
    created() {

    }
  }
</script>

<style lang="less" scoped>
  .detail {
    padding: 15rpx;

    /deep/.u-back-top {
      background-color: rgba(0, 0, 0, 0.1);
      color: #ffffff;
      border: 1px solid #9f9f9f;
    }
  }
</style>
